#pragma once
#include <functional>
#include <SDL2/SDL.h>
// typedef std::function<void(int )> win_event;


class SDL2Player {
public:
    enum PixFormat {
        I420,
        YUYV,
        NV12,
        NV21,
        RGB,
    };
    enum SDLEvent{
        QUIT,
        TERMINATING,
        NOTHING
    };

    enum SDLWindowsFlag{
        SDL_WINDOW_FULLSCREEN = 0x00000001,
        SDL_WINDOW_FULLSCREEN_DESKTOP = ( SDL_WINDOW_FULLSCREEN | 0x00001000 ),
        SDL_WINDOW_SHOWN = 0x00000004,
    };
public:
    SDL2Player();
    ~SDL2Player();
 
    void Init(uint32_t width, uint32_t height, PixFormat pix_format);
    bool isInit();
    void CreateRenderWindow(enum SDLWindowsFlag flag =  SDL_WINDOW_SHOWN, int x = SDL_WINDOWPOS_UNDEFINED, int y = SDL_WINDOWPOS_UNDEFINED);
    void SetWindow(void* handle);
    void Render(char* data);
    void GetCurrentScreenSize(uint32_t& width, uint32_t& height);
    enum SDL2Player::SDLEvent GetEvent() ;
private:
    void Init();
    void Destroy();
    void InitRender();
    void InitTexture();
 
private:
    uint32_t width_{};
    uint32_t height_{};
    PixFormat pix_format_ = I420;
 
    SDL_Window* window_{}; // 窗口
    SDL_Renderer* renderer_{}; // 渲染器
    SDL_Texture* texture_{}; // 纹理


    bool isInit_;
};
